<template>
  <el-card class="list-page">
    <div class="list-h">
      <div class="add-option"></div>
      <el-form
        :inline="true"
        class="demo-form-inline"
        :model="formSearch"
        ref="formRef"
      >
        <el-form-item label="审批事项" prop="billNameLike">
          <el-input
            clearable
            class="width-custom120"
            v-model="formSearch.billNameLike"
          ></el-input>
        </el-form-item>
        <el-form-item label="项目名称" prop="projectNameLike">
          <el-input
            v-model.trim="formSearch.projectNameLike"
            clearable
            class="width-custom120"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button @click="handleReset">重置</el-button>
          <el-button
            type="primary"
            @click="handleSearch"
            v-auth="`/approval/toread--query`"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <el-skeleton style="height: 50vh" :rows="8" :loading="loading" animated>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        v-loading="loading"
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
      >
        <template #empty>
          <el-empty :image-size="150" description="暂无数据"></el-empty>
        </template>

        <el-table-column type="index" label="序号" width="50">
          <template v-slot="scope">
            <span>{{
              (formSearch.pageNum - 1) * formSearch.pageSize + scope.$index + 1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="billName" label="审批事项"> </el-table-column>
        <el-table-column prop="billNum" label="事项编号"></el-table-column>
        <el-table-column prop="starterName" label="提交人"> </el-table-column>
        <el-table-column prop="lastUpdateTime" label="到达时间" width="160">
        </el-table-column>
        <el-table-column label="当前环节">
          <template #default="{ row }">
            <span class="text--info">
              {{ row.nodeStatusName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="当前处理人">
          <template #default="{ row }">
            <span class="text--info">
              {{ row.accepterName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="80">
          <template #default="{ row }">
            <el-button
              type="text"
              size="small"
              @click="handleDetail(row)"
              v-auth="`/approval/toread--look`"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <re-pagination
        v-if="total > 0"
        :total="total"
        v-model:page="formSearch.pageNum"
        v-model:limit="formSearch.pageSize"
        @pagination="handleSearch"
      />
    </el-skeleton>
  </el-card>
</template>

<script lang="ts">
import { reactive, ref, defineComponent } from "vue";
import { useRouter } from "vue-router";
import { flowQueryNotify } from "/@/api/approval";
import { storageLocal } from "/@/utils/storage";
export default defineComponent({
  setup() {
    const formRef = ref<HTMLFormElement | null>(null) as any;
    let formSearch = reactive({
      accepter: storageLocal.getItem("rdms-info")?.userId,
      feedback: "Y",
      billNameLike: "",
      projectNameLike: "",
      pageNum: 1,
      pageSize: 10
    });
    const router = useRouter();
    let loading = ref<boolean>(false);
    let tableData = ref([]);
    let total = ref<number>(0);
    const getTableData = async () => {
      loading.value = true;
      const { code, data } = await flowQueryNotify(formSearch);
      loading.value = false;
      if (code === 200) {
        tableData.value = data.list;
        total.value = data.rows;
      }
    };

    const handleDetail = row => {
      let pathUrl = "/approval/detail";
      let pathQuery = {
        flowType: row.billType,
        id: row.flowBaseId,
        readId:row.id,
        flowId: row.flowId,
        instanceId: row.procInstId,
        nodeId:row?.nodeId?.toUpperCase() || row?.nodeId?.nodeStatusCode || "ACT_010",
        preNodeId: row?.preNodeId?.toUpperCase(),
        billName: row.billName,
        busCategoryName: row.busCategoryName,
        busCategoryCode: row.busCategoryCode,
        projectManageId: row.projectManageId,
        mode: "read",
        isSkipLx: row.isSkipLx
      };
      router.push({
        path: pathUrl,
        query: pathQuery
      });
    };

    const handleReset = (): void => {
      formRef.value.resetFields();
    };

    const handleSearch = () => {
      getTableData();
    };

    getTableData();
    return {
      formRef,
      formSearch,
      loading,
      total,
      tableData,
      handleReset,
      handleSearch,
      handleDetail
    };
  }
});
</script>

<style lang="scss" scoped></style>
